package com.kinyx.framework.reflect;

import java.io.Serializable;

import org.junit.Assert;
import org.junit.Test;

public class KClassUtils_Tester_getSerialVersionUID {

	@Test(expected = NullPointerException.class)
	public void test1() {
		Assert.assertNull(KClassUtils.getSerialVersionUID(null));
	}

	// 没有实现Serializable接口
	public static class Bad0 {
		@SuppressWarnings("unused")
		private static final long serialVersionUID = 0L;
	}

	// 非static
	@SuppressWarnings("serial")
	public static class Bad1 implements Serializable {
		@SuppressWarnings("unused")
		private final long serialVersionUID = 1L;
	}

	// 非final
	@SuppressWarnings("serial")
	public static class Bad2 implements Serializable {
		@SuppressWarnings("unused")
		private static long serialVersionUID = 1L;
	}

	// 非long
	@SuppressWarnings("serial")
	public static class Bad3 implements Serializable {
		@SuppressWarnings("unused")
		private static final int serialVersionUID = 1;
	}

	public static class Good implements Serializable {
		private static final long serialVersionUID = 1L;
	}

	@Test
	public void test2() {
		Assert.assertNull(KClassUtils.getSerialVersionUID(Object.class));
		Assert.assertNull(KClassUtils.getSerialVersionUID(Serializable.class));

		Assert.assertNull(KClassUtils.getSerialVersionUID(Bad0.class));// not implements Serializable
		Assert.assertNull(KClassUtils.getSerialVersionUID(Bad1.class));// not static
		Assert.assertNull(KClassUtils.getSerialVersionUID(Bad2.class));// not final
		Assert.assertNull(KClassUtils.getSerialVersionUID(Bad3.class));// not long

		Assert.assertNotNull(KClassUtils.getSerialVersionUID(Good.class));
	}

}
